package com.wanshi.servlet;

import com.wanshi.dao.UserDao;
import com.wanshi.entity.User;
import com.wanshi.service.UserService;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

@WebServlet("/ss/findCond")
public class FindCondServlet extends HttpServlet {

    private UserService userService = new UserService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        User user = new User();
        //前提 表单中表单元素的name属性值 和 对象的属性一致
        try {
            BeanUtils.copyProperties(user,request.getParameterMap());

            List<User> list = userService.findByCond(user);

            request.setAttribute("list",list);
            request.getRequestDispatcher("/list.jsp").forward(request,response);
            //System.out.println(user);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

